package com.rxt.thermopro.viewmodel

import androidx.lifecycle.MutableLiveData
import com.app.common.viewmodel.BaseViewModel
import com.rxt.thermopro.app.LocalDataDao
import com.rxt.thermopro.bean.ProfileBean

class TempGraphViewModel : BaseViewModel() {
    val profileData: MutableLiveData<ProfileBean> = MutableLiveData()
    val tempNumData: MutableLiveData<String> = MutableLiveData()

    fun getProfile(position: Int, address:String) {
        val profile = when (position) {
            0 -> {
                LocalDataDao.INSTANCE.getProfile1(address)
            }
            1 -> {
                LocalDataDao.INSTANCE.getProfile2(address)
            }
            2 -> {
                LocalDataDao.INSTANCE.getProfile3(address)
            }
            3 -> {
                LocalDataDao.INSTANCE.getProfile4(address)
            }
            else -> LocalDataDao.INSTANCE.getProfile1(address)
        }
        profileData.value = profile
    }

    fun setTempNum(tempNumList: ArrayList<String>,currentPosition: Int) {
        if (tempNumList.isEmpty()){
            tempNumData.value = "N/A"
        } else if (tempNumList.size == 2) {
            if (currentPosition <= 1) {
                if (tempNumList[currentPosition].isNotEmpty()) {
                    tempNumData.value =
                            LocalDataDao.INSTANCE.convertUnit(tempNumList[currentPosition])
                } else {
                    tempNumData.value = "N/A"
                }
            } else {
                tempNumData.value = "N/A"
            }
        } else {
            if (tempNumList[currentPosition].isNotEmpty()) {
                tempNumData.value =
                    LocalDataDao.INSTANCE.convertUnit(tempNumList[currentPosition])
            } else {
                tempNumData.value = "N/A"
            }
        }
    }

}